package com.west_traveler.find_page_fragment.cate_fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.west_traveler.entity.entity_category.entity_category_second.Entity_Cate_Fra;
import com.west_traveler.entity.entity_category.entity_category_second.Entity_Cate_Fra_tag_en;
import com.west_traveler.find_page_fragment.AnchorFragment;
import com.west_traveler.find_page_fragment.CategoryFragment;
import com.west_traveler.find_page_fragment.LiveFragment;
import com.west_traveler.find_page_fragment.RankingFragment;
import com.west_traveler.find_page_fragment.RecommendFragment;

import java.util.List;

/**
 * Created by Administrator on 12/8 0008.
 */

public class Cate_FraPagerAdapter extends FragmentStatePagerAdapter {

    private Entity_Cate_Fra data;
    private final List<Entity_Cate_Fra_tag_en> tab_list;


    public Cate_FraPagerAdapter(FragmentManager fm, Entity_Cate_Fra data) {
        super(fm);
        this.data = data;
        //处理数据
        tab_list = data.getTags().getList();
        Entity_Cate_Fra_tag_en en = new Entity_Cate_Fra_tag_en();
        en.setTname("推荐");
        tab_list.add(0,en);
    }

    @Override
    public Fragment getItem(int position) {
        //根据ViewPager的位置索引，返回对应Fragment的实例
        Bundle bundle = null;
        switch (position) {
            case 0:
                Cate_RecomFragment recomFragment = Cate_RecomFragment.getInstance();
                bundle = new Bundle();
                bundle.putParcelable("data",data);
                recomFragment.setArguments(bundle);
                return recomFragment;
            default:
                Cate_SingleFragment cateSingleFragment = Cate_SingleFragment.getInstance();
                String tname = tab_list.get(position).getTname();
                int categoryId = tab_list.get(position).getCategory_id();
                bundle = new Bundle();
                bundle.putString("categoryId",categoryId+"");
                bundle.putString("tagName",tname);
                cateSingleFragment.setArguments(bundle);
                return cateSingleFragment;

        }
    }

    @Override
    public int getCount() {
        return tab_list.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tab_list.get(position).getTname();
    }
}
